﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace JZ_ERP.Common
{
    public class CommandBase : ICommand
    {
        public CommandBase()
        {

        }
        public CommandBase(Action<object> doExecute, Func<object, bool> doCanExecute)
        {
            DoExecute = doExecute;
            DoCanExecute = doCanExecute;
        }
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return DoCanExecute?.Invoke(parameter)==true;   //DoCanExecute为空时需要强转类型，==true即为true时返回true否则返回false
        }

        public void Execute(object parameter)
        {
            DoExecute?.Invoke(parameter);
        }

        public Action<object> DoExecute { get; set; }
        public Func<object,bool> DoCanExecute { get; set; }


        public void OnCanExecuteChanged()
        {
            CanExecuteChanged?.Invoke(this, new EventArgs());
        }
    }
}
